class Solution {
    public int[] searchRange(int[] nums, int target) {
        // 条件 nums[left] >= target && nums[right] <= target
        int left = 0;
        int right = nums.length;
        int mid = 0;
        while (left < right) {
            mid = (left + right) >> 1;
            if (nums[mid] >= target) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        int start = right;
        left = -1;
        right = nums.length - 1;
        while (left < right) {
            mid = (left + right + 1) >> 1;
            if (nums[mid] <= target) {
                left = mid;
            } else {
                right = mid - 1;
            }
        }
        int end = right;
        if (start > end) return new int[]{-1, -1};
        return new int[]{start, end};
    }
}
